<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Form Layouts</title>

    <link href="<%=path%>/resources/css/style.css" rel="stylesheet">
    <link href="<%=path%>/resources/css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="<%=path%>/resources/js/html5shiv.js"></script>
    <script src="<%=path%>/resources/js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="sticky-header">

<section>
    <!-- left side start-->
    <%@ include file="/page/common/leftmenu.jsp" %>
    <!-- left side end-->

    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <%@ include file="/page/common/top.jsp" %>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>

            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">管理平台</a>
                </li>
                <li class="active">用户管理</li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper">
            <!-- page start-->
            <div class="row">
                <div class="col-lg-12">
                    <style>
                        .label-right label{padding-right: 0;margin-top: 5px;width: auto}
                    </style>
                    <div class="panel">
                        <div class="panel-heading" style="background-color: transparent">
                            <h3 class="panel-title">条件筛选</h3>
                        </div>
                        <div class="panel-body toolbar">
                            <div class="row label-right">
                                <label class="col-md-1 control-label font-inherit"> 省: </label>
                                <div class="col-md-2">
                                    <select id="province-select" class="form-control selectpicker" data-live-search="true">
                                        <option value="-1">全部</option>
                                    </select>
                                </div>
                                <label class="col-md-1 control-label font-inherit"> 市：</label>
                                <div class="col-md-2">
                                    <select id="city-select" class="form-control selectpicker" data-live-search="true">
                                        <option value="-1">全部</option>
                                    </select>
                                </div>
                                <label class="col-md-1 control-label font-inherit"> 区：</label>
                                <div class="col-md-2">
                                    <select id="area-select" class="form-control selectpicker" data-live-search="true">
                                        <option value="-1">全部</option>
                                    </select>
                                </div>
                            <%--</div>
                            <br>
                            <div class="row">--%>
                                <label class="col-md-1 control-label font-inherit"> 手机号：</label>
                                <div class="col-md-2">
                                    <input id="phone" class="form-control" type="text" placeholder="请输入手机号">
                                </div>
                                <div class="col-md-1">
                                    <span class="input-group-btn">
                                        <button type="button"  onclick="search()" class="btn btn-primary">查询</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="table table-striped table-hover table-bordered" id="editable-sample">
                <div class="table-responsive" data-pattern="priority-columns" data-focus-btn-icon="fa-asterisk"
                     data-sticky-table-header="true" data-add-display-all-btn="true" data-add-focus-btn="true">
                    <table id="table" data-unique-id="id"
                           data-pagination="true"
                           data-id-field="id"
                           data-maintain-selected="true"
                           data-page-size="10"
                           data-page-list="[5,10,15,20]"
                           data-side-pagination="server">
                    </table>
                </div>
            </div>
            <!-- page end-->
        </section>


        <!--body wrapper end-->

        <!--footer section start-->
        <%@ include file="/page/common/footer.jsp" %>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<script src="<%=path%>/resources/js/jquery-1.10.2.min.js"></script>
<script src="<%=path%>/resources/js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="<%=path%>/resources/js/jquery-migrate-1.2.1.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap-table.js"></script>

<script src="<%=path%>/resources/js/modernizr.min.js"></script>
<script src="<%=path%>/resources/js/jquery.nicescroll.js"></script>
<script src="<%=path%>/resources/js/common.js"></script>

<!--common scripts for all pages-->
<script src="<%=path%>/resources/js/scripts.js"></script>
<script>
    var offset = -1;
    var $table = $('#table'), selections = [];
    $(function () {
        init_province();
        initData();
    });

    //初始化省信息
    function init_province() {
        $.ajax({
            url: '<%=path %>/admin/addressInfo/init_address.do',
            async: false,
            success: function (data) {
                $.each(data.data, function (idx, obj) {
                    var value = obj.id;
                    $('#province-select').append('<option value=' + value + '>' + obj.name + '</option>')
                });
            }
        });
    }

    //初始化市信息
    function init_city() {
        $.ajax({
            url: '<%=path %>/admin/addressInfo/init_address.do?pid=' + $('#province-select').val(),
            async: false,
            success: function (data) {
                $.each(data.data, function (idx, obj) {
                    var value = obj.id;
                    $('#city-select').append('<option value=' + value + '>' + obj.name + '</option>')
                });
            }
        });
    }

    /*初始化表格数据*/
    function initData() {
        $('#table').bootstrapTable({
            url: "<%=request.getContextPath() %>/admin/cust/queryCustomers.do",
            //clickToSelect: 'true',//选中一行
            queryParams: queryParams,
            columns: [{
                field: 'SerialNumber',
                title: '序号',
                width: '80',
                formatter: function (value, row, index) {
                    return index+1;
                }
            }, {
                field: 'user.logo',
                title: '微信头像',
                width: '150',
                align: 'center',
                formatter: 'logoFormatter',
            }, {
                field: 'user.phone',
                title: '用户名',
                width: '150',
                align: 'center',
            }, {
                field: 'user.wName',
                title: '微信号',
                width: '150',
                align: 'center',
            }, {
                field: 'address',
                title: '地址',
                width: '350',
                align: 'center',
            }, {
                field: 'crtTime',
                title: '注册时间',
                width: '150',
                align: 'center',
            }],
        });
    }

    //选择省
    $('#province-select').on("change", function () {
        if ($('#province-select').val() == -1) {
            $('#province-select').find('option').remove();
            $('#city-select').find('option').remove();
            $('#area-select').find('option').remove();
            $('#province-select').append("<option value='-1'>全部</option>");
            $('#city-select').append("<option value='-1'>全部</option>");
            $('#area-select').append("<option value='-1'>全部</option>");
            init_province();
        } else {
            $.ajax({
                url: '<%=basePath %>/admin/addressInfo/init_address.do?pid=' + $('#province-select').val(),
                async: false,
                success: function (data) {
                    $('#city-select').find('option').remove();
                    $('#area-select').find('option').remove();
                    $('#area-select').append("<option value='-1'>全部</option>");
                    $('#city-select').append("<option value='-1'>全部</option>");
                    $.each(data.data, function (idx, obj) {
                        var value = obj.id;
                        $('#city-select').append('<option value=' + value + '>' + obj.name + '</option>')
                    });
                }
            });
        }
    });

    //选择市
    $('#city-select').on("change", function () {
        if ($('#city-select').val() == -1) {
            $('#city-select').find('option').remove();
            $('#area-select').find('option').remove();
            $('#city-select').append("<option value='-1'>全部</option>");
            $('#area-select').append("<option value='-1'>全部</option>");
            init_city();
        } else {
            $.ajax({
                url: '<%=basePath %>/admin/addressInfo/init_address.do?pid=' + $('#city-select').val(),
                async: false,
                success: function (data) {
                    //$('#city-select').find('option').remove();
                    $('#area-select').find('option').remove();
                    $('#area-select').append("<option value='-1'>全部</option>");
                    //$('#city-select').append("<option value='-1'>全部</option>");
                    $.each(data.data, function (idx, obj) {
                        var value = obj.id;
                        $('#area-select').append('<option value=' + value + '>' + obj.name + '</option>')
                    });
                }
            });
        }
    });

    /*刷新*/
    function search() {
        offset = 0;
        $table.bootstrapTable('refresh');
    }

    /**封装查询条件**/
    function queryParams(params) {
        if (offset == 0) {
            params.offset = offset;
        }
        offset = -1;
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,  //页面大小
            offset: params.offset, //页码
            phone: $("#phone").val(),
            proId: $("#province-select").val(),
            cityId: $("#city-select").val(),
            areaId: $("#area-select").val(),
            maxrows: params.limit,
            pageindex: params.pageNumber
        };
        return temp;
    }

    function logoFormatter(value){
        var context="<img width='100px' height='30px' src='" + value + "'>"
        return context;
    }

    jQuery(document).ready(function($)
    {
        selectEffect("admin/cust/customer_list_page.do");
    });
</script>
</body>
</html>

